package com.spark.common.ui

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.Window
import android.view.WindowManager
import com.spark.common.BaseActivity
import com.spark.common.R
import com.spark.common.ext.server
import kotlinx.android.synthetic.main.act_image.*

class ImageActivity : BaseActivity() {
    companion object {
        fun actionStart(host: Activity, url: String) {
            val intent = Intent(host, ImageActivity::class.java)
            intent.putExtra("url", url)
            host.startActivity(intent)
        }
    }

    override fun contentResId(): Int {
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
        return R.layout.act_image
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        intent?.apply {
            getStringExtra("url")?.apply {
                if (!this.isNullOrBlank())
                    photo_view.server(this)
            }
            photo_view.setOnClickListener { finish() }
        }
    }
}